home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / MacMud / Mud 4.0 / dumpstat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-30  |  1.6 KB  |  74 lines  |  [TEXT/MPS ]

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include "lint.h"
  5. #include "interpret.h"
  6. #include "object.h"
  7. #include "exec.h"
  8. /*
  9.  * Write statistics about objects on file.
  10.  */
  11.  
  12. extern struct object *obj_list;
  13.  
  14. static int svalue_size(v)
  15.     struct svalue *v;
  16. {
  17.     int i, total;
  18.  
  19.     switch(v->type) {
  20.     case T_OBJECT:
  21.     case T_NUMBER:
  22.     return 0;
  23.     case T_STRING:
  24.     return strlen(v->u.string) + 4; /* Includes some malloc overhead. */
  25.     case T_MAPPING:
  26.     case T_POINTER:
  27.     for (i=0, total = 0; i < v->u.vec->size; i++) {
  28.         total += svalue_size(&v->u.vec->item[i]) + sizeof (struct svalue);
  29.     }
  30.     return total;
  31.     default:
  32.     fatal("Illegal type: %d\n", v->type);
  33.     }
  34.     /*NOTREACHED*/
  35. #ifdef lint
  36.     return 0;
  37. #endif
  38. }
  39.  
  40. static int data_size(ob)
  41.     struct object *ob;
  42. {
  43.     int total = 0, i;
  44.     if (ob->prog) {
  45.         for (i = 0; i < ob->prog->num_variables; i++)
  46.             total += svalue_size(&ob->variables[i]) + sizeof (struct svalue);
  47.     }
  48.     return total;
  49. }
  50.  
  51. void dumpstat() {
  52.     FILE *f;
  53.     struct object *ob;
  54.  
  55.     f = fopen("OBJ_DUMP", "w");
  56.     if (f == 0)
  57.     return;
  58.     add_message("Dumping to OBJ_DUMP ...");
  59.     for (ob = obj_list; ob; ob = ob->next_all) {
  60.     int tmp;
  61.     if (ob->prog && (ob->prog->ref == 1 || !(ob->flags & O_CLONE)))
  62.         tmp = ob->prog->total_size;
  63.     else
  64.         tmp = 0;
  65.     fprintf(f, "%-20s %5d ref %2d %s %s (%ld) %s\n", ob->name,
  66.         tmp + data_size(ob) + sizeof (struct object), ob->ref,
  67.         ob->flags & O_HEART_BEAT ? "HB" : "  ",
  68.         ob->super ? ob->super->name : "--",/*ob->cpu*/ 0,
  69.         ob->swap_num >=0 ? "SWAPPED" : "");
  70.     }
  71.     add_message("done.\n");
  72.     fclose(f);
  73. }
  74.